//
//  String+Extension.swift
//  Weibo
//
//  Created by lzing on 16/3/30.
//  Copyright © 2016年 lzing. All rights reserved.
//

import Foundation

extension String {
    func sinaSource() -> String {
        // 正则匹配模型
        let pattern = ">(.*?)<"
        // 创建正则
        let regular = try! NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        // 匹配结果
        let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSRange(location: 0, length: self.characters.count))
        // 匹配个数
        let count = result?.numberOfRanges ?? 0
        if count > 1 {
            let range = result!.rangeAtIndex(1)
            return (self as NSString).substringWithRange(range)
        }
        return "未知来源"
    }
}